package palmtop.com.palmtop.activity;

import android.os.Bundle;
import android.webkit.WebView;

import com.beardedhen.androidbootstrap.AwesomeTextView;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.BindView;
import butterknife.ButterKnife;
import palmtop.com.palmtop.R;
import palmtop.com.palmtop.model.InfoDissemina;
import palmtop.com.palmtop.util.Config;

public class InfodetailActivity extends BaseActivity {

    @BindView(R.id.mTitle)
    AwesomeTextView mTitle;
    @BindView(R.id.mContentView_art)
    WebView mContentViewArt;

    InfoDissemina infoDissemina;
    private String content;
    private String title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_infodetail, Config.toptitle, 1);
        ButterKnife.bind(this);
        loadView();
    }

    private void loadView() {
        infoDissemina = (InfoDissemina)getIntent().getSerializableExtra("info");
        if(infoDissemina!=null){
            title=infoDissemina.getTitle();
            content=infoDissemina.getContent();
            Pattern p= Pattern.compile("\"(.*?)\"");
            if(content!=null){
                Matcher m=p.matcher(content);
                while(m.find()){
                    if(m.group().indexOf(".jpg")!=-1||m.group().indexOf(".png")!=-1){
                        String newstr = m.group().replace("\"","");
                        content = content.replace(m.group(),"\""+Config.IMG_URL+newstr+"\"");
                    }
                }
                mContentViewArt.loadDataWithBaseURL(null,content,"text/html" , "utf-8", null);
            }
            mTitle.setText(title);


        }else{
            mContentViewArt.loadDataWithBaseURL(null,"空","text/html" , "utf-8", null);

        }

    }
}
